/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.datasource.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.snail.server.database.engine.datasource.entity.DataSource;
import com.snail.server.database.engine.datasource.mapper.DataSourceMapper;
import com.snail.starter.db.enums.EnableOrDisEnableEnum;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zgadmin
 * @date 2025/8/28 17:40
 */
@Service
public class DataSourceService extends ServiceImpl<DataSourceMapper, DataSource> {

    public DataSource queryById(Long dataSourceId, EnableOrDisEnableEnum status) {
        return getOne(Wrappers.lambdaQuery(DataSource.class)
                .eq(DataSource::getDataSourceId, dataSourceId)
                .eq(DataSource::getStatus, status)
        );
    }

    public DataSource queryById(Long dataSourceId) {
        return getOne(Wrappers.lambdaQuery(DataSource.class)
                .eq(DataSource::getDataSourceId, dataSourceId)
        );
    }

    public List<DataSource> selectAll(EnableOrDisEnableEnum status) {
        return list(Wrappers.lambdaQuery(DataSource.class)
                .eq(DataSource::getStatus, status)
        );
    }

    public boolean delete(Long dataSourceId) {
        return remove(Wrappers.lambdaQuery(DataSource.class).eq(DataSource::getDataSourceId, dataSourceId));
    }

    public Boolean modify(Long dataSourceId, DataSource dataSource) {
        return update(dataSource, Wrappers.lambdaQuery(DataSource.class).eq(DataSource::getDataSourceId, dataSourceId));
    }
}